package com.yugong.controller;

import com.github.pagehelper.PageInfo;
import com.yugong.common.Result;
import com.yugong.entity.vo.request.BusinessRequestVO;
import com.yugong.entity.vo.request.StudentRequestVO;
import com.yugong.entity.vo.response.BusinessListResponseVO;
import com.yugong.entity.vo.response.OrderClassListResponseVO;
import com.yugong.entity.vo.response.StudentListResponseVO;
import com.yugong.service.BusinessService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 企业管理器类
 *
 * @author yugong
 * @date 2024/2/18
 */
@RestController
@RequestMapping("/api/business")
public class BusinessController {
    @Resource
    private BusinessService businessService;

    /**
     * 查询企业信息
     *
     * @return 企业信息
     */
    @GetMapping("/find-business")
    public Result findBusiness() {
        List<BusinessListResponseVO> businessVOList = businessService.findBusiness();
        return Result.success(businessVOList);
    }

    /**
     * 根据企业名查询企业信息
     *
     * @param pageNum      当前页
     * @param pageSize     当前页数据总数
     * @param businessName 企业名
     * @return 企业信息
     */
    @GetMapping("/find-business-page")
    public Result findBusinessPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                   @RequestParam(defaultValue = "5") Integer pageSize,
                                   @RequestParam String businessName) {
        PageInfo<BusinessListResponseVO> businessListResponseVOPageInfo =
                businessService.findBusiness(pageNum, pageSize, businessName);
        return Result.success(businessListResponseVOPageInfo);
    }

    /**
     * 修改企业
     *
     * @param businessRequestVO 企业请求实体类
     * @return 响应码
     */
    @PutMapping("/update-business")
    public Result updateBusiness(@RequestBody BusinessRequestVO businessRequestVO) {
        int updateFlag = businessService.updateBusiness(businessRequestVO);
        return Result.success(updateFlag);
    }

    /**
     * 删除企业
     *
     * @param businessNo 企业号
     * @return 响应码
     */
    @DeleteMapping("/delete-business/{businessNo}")
    public Result deleteBusiness(@PathVariable String businessNo) {
        int deleteFlag = businessService.deleteBusiness(businessNo);
        return Result.success(deleteFlag);
    }

    /**
     * 查询企业个人信息
     *
     * @param businessNo 企业号
     * @return 企业个人信息
     */
    @GetMapping("/business-info/{businessNo}")
    public Result businessInfo(@PathVariable String businessNo) {
        BusinessListResponseVO businessListResponseVO = businessService.businessInfo(businessNo);
        return Result.success(businessListResponseVO);
    }

    /**
     * 修改信息
     *
     * @param businessRequestVO 企业请求实体类
     * @return 响应码
     */
    @PutMapping("/update-info")
    public Result updateInfo(@RequestBody BusinessRequestVO businessRequestVO) {
        int updateFlag = businessService.updateInfo(businessRequestVO);
        return Result.success(updateFlag);
    }

    /**
     * 查看企业自己的学生评价
     *
     * @param pageNum     当前页
     * @param pageSize    当前页总数
     * @param studentName 姓名
     * @param businessNo  企业号
     * @return 企业自己的学生评价
     */
    @GetMapping("/find-student/{businessNo}")
    public Result findStudent(@RequestParam Integer pageNum,
                              @RequestParam Integer pageSize,
                              @RequestParam String studentName,
                              @PathVariable String businessNo) {
        PageInfo<StudentListResponseVO> studentListResponseVOPageInfo
                = businessService.findStudent(pageNum, pageSize, studentName, businessNo);
        return Result.success(studentListResponseVOPageInfo);
    }

    /**
     * 企业录用
     *
     * @param studentRequestVO 学生请求实体类
     * @return 响应码
     */
    @PutMapping("/employment-student")
    public Result employmentStudent(@RequestBody StudentRequestVO studentRequestVO) {
        int flag = businessService.employmentStudent(studentRequestVO);
        return Result.success(flag);
    }

    /**
     * 查询订单班
     *
     * @param pageNum        当前页
     * @param pageSize       当前页个数
     * @param orderClassName 班名
     * @param businessNo     企业号
     * @return 订单班
     */
    @GetMapping("/find-order-class/{businessNo}")
    public Result findOrderClass(@RequestParam(defaultValue = "1") Integer pageNum,
                                 @RequestParam(defaultValue = "5") Integer pageSize,
                                 @RequestParam String orderClassName,
                                 @PathVariable String businessNo) {
        PageInfo<OrderClassListResponseVO> orderClassListResponseVOPageInfo
                = businessService.findOrderClass(pageNum, pageSize, orderClassName, businessNo);
        return Result.success(orderClassListResponseVOPageInfo);
    }
}
